<?php
namespace app\api\controller;

class AdminRules extends Permission
{
    public function getRulesByAdminId()
    {
        $map['admin_id'] = $this->input_data['id'];
        
        $list = db('AdminRules')->where($map)->select();
        $rules = [];
        // 只返回子节点的id
        $parent = [81,111,116,119,125,130,137,141,143];
        foreach ($list as $v) {
            if(!in_array($v['router_id'] ,$parent)) $rules[] = $v['router_id'];
        }
        $this->resSuc($rules);
    }

    public function update()
    {
        if( !in_array($this->user['id'], config('rulesManageIds')) ) $this->resErr('您无权修改账号权限');
        $map['admin_id'] = $this->input_data['adminId'];

        db('AdminRules')->where($map)->delete();
        $ids = json_decode($this->input_data['ids'],TRUE);
        $data = [];
        foreach ($ids as $v) {
            $router['admin_id'] = $this->input_data['adminId'];
            $router['router_id'] = $v;
            $data[] = $router;
        }
        db('AdminRules')->insertAll($data);
        $this->resSuc('success');
    }

}
